﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WaterRegimenMonitor.Web.DataModel;

namespace WaterRegimenMonitor.Web.Domain
{
    /// <summary>
    /// 用户角色辅助类。
    /// </summary>
    public class RoleHelper
    {
        /// <summary>
        /// 获得指定用户的角色信息。
        /// </summary>
        /// <param name="targetUser">用户信息。</param>
        /// <returns></returns>
        public static List<Role> GetRoleListByUser(User targetUser)
        {
            using (TalimuEntities context = new TalimuEntities())
            {
                return (from role in context.Role
                        join userRole in context.UserRole on role.RoleID equals userRole.RoleID
                        join user in context.User on userRole.UserID equals user.UserID
                        where user.UserID == targetUser.UserID
                        select role).ToList();
            }
        }
    }
}